package com.huangge1199.common.util;

import lombok.Data;
import lombok.ToString;

/**
 * @Author: huang
 * @Description 返回前端数据
 * @Date: 2021-01-02 09:09
 */
@Data
@ToString
public class Response<T> {

    private String code;
    private String msg;
    private T data;

    /**
     * 失败，带错误码、错误信息
     *
     * @param code 错误码
     * @param msg  错误信息
     */
    public Response(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 失败，带返回信息
     *
     * @param msg 错误信息
     */
    public Response(String msg) {
        this.code = "-1";
        this.msg = msg;
    }

    /**
     * 成功，带返回信息
     *
     * @param msg  成功提示语
     * @param data 数据
     */
    public Response(String msg, T data) {
        this.code = "0";
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功
     * @param data 数据
     */
    public Response(T data) {
        this.code = "0";
        this.msg = "success";
        this.data = data;
    }

    /**
     * 成功没有，无返回数据
     */
    public Response() {
        this.code = "0";
        this.msg = "success";
    }
}
